#include "video.h"

int init_video(Screen *pScreen)
{
    /*    printf("init_video()\n"); */
    const SDL_VideoInfo* info = NULL;

    if (SDL_Init(SDL_INIT_VIDEO) < 0 )
    {
        fprintf(stderr, "Video initialization failed: %s\n", SDL_GetError());
        return 0;
    }

    info = SDL_GetVideoInfo();
    pScreen->mBpp = info->vfmt->BitsPerPixel;

    printf("Screen mode: %dx%dx%x\n", pScreen->mWidth, pScreen->mHeight, pScreen->mBpp);

    SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
    SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5);
    SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
    SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
    SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);

    pScreen->mFlags = SDL_OPENGL;

    if (SDL_SetVideoMode(pScreen->mWidth, pScreen->mHeight, pScreen->mBpp, pScreen->mFlags) == 0)
    {
        fprintf(stderr, "Video mode set failed: %s\n", SDL_GetError());
        return 0;
    }

    return 1;
}

int deinit_video()
{
    /*    printf("deinit_video()\n"); */
    SDL_Quit();
}
